package opensocial.apps.treat.model
{
  import mx.collections.ArrayCollection;
  public class Invitation
  {
    public function Invitation(master:User, id:Number = -1, guests:ArrayCollection = null, startTime:Date = null, place:Place = null) {
      _id = id;
      _master = master;
      _guests = (guests) ? guests : new ArrayCollection();
      _startTime = startTime;
      _place = place;
      _endTime = new Date();
      _startTime && _endTime.setTime(_startTime.getTime());
      _endTime && _place && _endTime.setMinutes(_endTime.getMinutes() + _place.stay);
      _accept = new ArrayCollection();
      _declined = new ArrayCollection();
      var tUnresponsive: ArrayCollection = new ArrayCollection();
      for each (var u: User in guests)
      	tUnresponsive.addItem(u);
      _unresponsive = tUnresponsive;
      _uninvited = new ArrayCollection();
      _status = 1;
    }
    
    private var _id:Number;
    
    public function set id(value:Number):void {
      _id = value;
    }
    
    public function get id():Number {
      return _id;
    }
    
    private var _master:User;
    
    public function set master(value:User):void {
      _master = value;
    }
    
    public function get master():User {
      return _master;
    }
    
    private var _guests:ArrayCollection;
    
    public function set guests(value:ArrayCollection):void {
      _guests = value;
    }
    
    public function get guests():ArrayCollection {
      return _guests;
    }
    
   
    private var _startTime:Date;
    
    public function set startTime(value:Date):void {
      _startTime = value;
      if (_place) {
        _endTime = new Date();
        _endTime.setTime(_startTime.getTime());
        _endTime.setMinutes(_endTime.getMinutes() + _place.stay);        
      }
    }
    
    public function get startTime():Date {
      return _startTime;
    }
    
    private var _endTime:Date;
    
    public function set endTime(value:Date):void {
      _endTime = value;
    }
    
    public function get endTime():Date {
      return _endTime;
    }
    
    private var _place:Place;
     
    public function set place(value:Place):void {
      _place = value;
      _endTime = new Date();
      _endTime.setTime(_startTime.getTime());
      _endTime.setMinutes(_endTime.getMinutes() + _place.stay);
    }
    
    public function get place():Place {
      return _place;
    }
    
   
    private var _accept:ArrayCollection; //赴约
    
    public function set accept(value:ArrayCollection):void {
      _accept = value;
    }
    
    public function get accept():ArrayCollection {
      return _accept;
    }
    
    
    private var _declined:ArrayCollection; //拒绝
    
    public function set declined(value:ArrayCollection):void {
      _declined = value;
    }
    
    public function get declined():ArrayCollection {
      return _declined;
    }
    
    
    private var _unresponsive:ArrayCollection; //未回复
     
    public function set unresponsive(value:ArrayCollection):void {
      _unresponsive = value;
    }
    
    public function get unresponsive():ArrayCollection {
      return _unresponsive;
    }
    
    private var _uninvited:ArrayCollection; // 未邀请（占座）
    
    public function set uninvited(value:ArrayCollection):void {
      _uninvited = value;
    }
    
    public function get uninvited():ArrayCollection {
      return _uninvited;
    }
    
    private var _emptySeat:Number;
 
 		public function set emptySeat(v: Number): void {
 			_emptySeat = v;
 		}
   
    public function get emptySeat():Number {
      if (status == 1) {
        _emptySeat = _master.level.seat - accept.length - uninvited.length;        
      } else {
        _emptySeat = _master.level.seat - guests.length - uninvited.length;
      }
      return _emptySeat;
    }
    
    private var _status:Number;
    
    public function set status(value:Number):void {
      _status = value;
    }
    
    public function get status():Number {
      return _status;
    }
    
    public function toString():String {
      return _place.name + ':' + _master.name + ':' + status;
    }
  }
}